#ifndef FUNC_TRAPZ_H
#define FUNC_TRAPZ_H
#include "cdecl.h"
#include <stdio.h>
#include "func_secondderr.h"

/**
 * The module provides function integrator, that estimates second 
 * derrivative to achieve necessary precision and performs integration 
 * using trapezoidal method.
 */
 
struct func_trapz_stats {
	 uint32_t nknot; // Number of knots used in integration (you would 
	 // like to get it to understand result_arr, if you use it)
	 double fii; // Second derrivative absolute value maximum
	 unsigned int nitr; // Number of iterations
};
 
 
 /**
  * Calculates `func` function integral over [a,b].
  * @param func - function pointer: x - variable, context - pointer to 
  * structure with configurations, understandible by function, 
  * contents depend on func
  * @param ctx - context for function being studied
  * @param a,b - integration diapason, a<b
  * @param eps - requested relative precision
  * @param result - place to put answer to
  * @param result_arr - pointer to malloced patch with complex integal 
  * values over every between-knot interval. Array length = 
  * stats -> nknot - 1. array[i] = \int\limits_{x_i}^{x_{i+1}}dx f(x).
  * Free()-ing the array is up to the user. NULL disables output.
  * @param stats - function statistics to output, NULL pointer
  * permitted to identify that nothing shall be output
  * @return	0 - success
  * 		1 - integer limit exceeded
  * 		2 - eps shall be < 1 to satisfy numerical assumptions
  * 		3 - mathematical algorythm failed
  * 		4 - out of memory
  * 		11...20 - second derrivatime max failed with status 10+x 
  */ 
int func_trapz(complex (*func)(double x, void * context), void * ctx, 
		double a, double b,
		double eps, complex * result, complex ** result_arr,
		struct func_trapz_stats * stats); 


#endif
